<?php

require('./core/Smarty_oRs.php');
require('./includes/config.php');
require('./includes/func_database.php');
require('./includes/func_signups.php');
require('./includes/func_player.php');
require('./includes/func_rp.php');
require('./includes/func_raid.php');
require('./includes/func_teams.php');
require('./includes/func_login.php');

session_start();

$dbh = initConnection();

$smarty = new Smarty_oRs;

$raid = new raid();
$player = new player;
$rp = new rp;
$signup = new signup();
$team = new team;
$user = new User();

$location = abs($_GET['location']);


if ($_SESSION['level'] >= 3 || $location == 2) {
	if (isset($_GET['action']) && $_GET['action'] == "up" && isset($_GET['p_id']) && isset($_GET['p_name']) && isset($_GET['p_class']) && isset($_GET['p_race']) && isset($_GET['p_team']) && isset($_GET['p_level'])) {


		$p_id = abs($_GET['p_id']);
		$p_name = $_GET['p_name'];
		$p_class = $_GET['p_class'];
		$p_race = $_GET['p_race'];
		$p_team = abs($_GET['p_team']);
		$p_level = abs($_GET['p_level']);

		$p_uid = abs($_GET['p_uid']);
		$p_row = $_GET['p_row'];
		$p_rp1 = abs($_GET['p_rp1']);
		$p_rp2 = abs($_GET['p_rp2']);
		$p_num = abs($_GET['p_num']);


		$player->save($p_id, 0, $p_name, $p_class, $p_race, $p_level, $p_team);

		$character_team = $team->get($p_team);

		$character['active']		=	1;
		$character['name']			=	$p_name;
		$character['class']			=	$p_class;
		$character['race']			=	$p_race;
		$character['level']			=	$p_level;
		$character['team_image']	=	$character_team[0]['team_image'];
		$character['team_name']		=	$character_team[0]['team_name'];
		$number						=	$p_num;
		$row						=	$p_row;

		$smarty->assign('row', $row);
		$smarty->assign('number', $number);
		$smarty->assign('character', $character);

		// location is send though an integer
		// 1 = standings
		// 2 = panel

		if ($location == 1) {

			$smarty->display('single_standing.tpl', $_SESSION['uid']);

		} elseif ($location == 2) {

			$smarty->display('single_panel.tpl', $_SESSION['uid']);

		}



	} elseif (isset($_GET['action']) && $_GET['action'] == "uu" && isset($_GET['u_id']) && isset($_GET['u_name']) && isset($_GET['u_username']) && isset($_GET['u_level']) && isset($_GET['u_password1']) && isset($_GET['u_password2'])) {

		global $_GLOBALSALT;

		$u_id = abs($_GET['u_id']);
		$u_name = $_GET['u_name'];
		$u_username= $_GET['u_username'];
		$u_password1 = $_GET['u_password1'];
		$u_password2 = $_GET['u_password2'];
		$u_level = abs($_GET['u_level']);
		$u_email = $_GET['u_email'];

		if (!empty($u_password1) && !empty($u_password2) && ($u_password1 == $u_password2)) {

			$salt = create_salt(5);

			$password = $u_password1;

		}


		$user->save($u_id, $u_name, $u_email, $password, $u_username, $u_level, $salt);
//
//		$character['active']		=	1;
//		$character['name']			=	$p_name;
//		$character['class']			=	$p_class;
//		$character['race']			=	$p_race;
//		$character['onyxia']		=	$p_onyxia;
//		$character['moltencore']	=	$p_moltencore;
//		$character['blackwinglair']	=	$p_blackwinglair;
//		$character['naxxramas']		=	$p_naxxramas;
//		$character['level']			=	$p_level;
//		$character['40M']			=	$p_rp1;
//		$character['20M']			=	$p_rp2;
//		$character['team_image']	=	$character_team[0]['team_image'];
//		$character['team_name']		=	$character_team[0]['team_name'];
//		$number						=	$p_num;
//		$row						=	$p_row;
//
//		$smarty->assign('row', $row);
//		$smarty->assign('number', $number);
//		$smarty->assign('character', $character);
//
//		// location is send though an integer
//		// 1 = standings
//		// 2 = panel
//
//		if ($location == 1) {
//
//			$smarty->display('single_standing.tpl', $_SESSION['uid']);
//
//		} elseif ($location == 2) {
//
//			$smarty->display('single_panel.tpl', $_SESSION['uid']);
//
//		}

		echo "<tr><td colspan=\"8\">User updated - Please refresh the page</td></tr>";



	}

}
?>